package com.zhongying.jf.util;

import java.util.List;
import java.util.Map;

import com.zhongying.jf.ResConstants;
import com.zhongying.jf.exception.ZhongyingiException;

/**
 * @author liyuxuan
 * @Description 校验参数是否为空的
 * @Email liyuxuan@chinazyjr.com Created on 2017/8/30 21:11 Copyright (c) 2017
 *        All Rights Reserved.
 */
public class ArrayIsNotNullUtil {

	public static void paramsValidate(Object... params) {
		if (null != params && params.length > 0) {
			for (int i = 0; i < params.length; i++) {
				if (isNull(params[i])) {
					throw new ZhongyingiException(ResConstants.PARAM_NOT_RIGHT.getCode(),
							ResConstants.PARAM_NOT_RIGHT.getMsg());
				}
			}
		} else {
			throw new ZhongyingiException(ResConstants.PARAM_NOT_RIGHT.getCode(),
					ResConstants.PARAM_NOT_RIGHT.getMsg());
		}
	}

	public static boolean isNull(Object o) {
		boolean result = false;
		if (null == o) {
			result = true;
		} else if (o instanceof List) {
			result = ((List) o).size() == 0;
		} else if (o instanceof Map) {
			result = ((Map) o).isEmpty();
		} else if (o.getClass() == String.class) {
			result = isEmpty(o.toString());
		}
		return result;
	}

	public static boolean isEmpty(String s) {
		boolean result = false;
		if ("".equals(s)) {
			result = true;
		}
		return result;
	}

}
